package com.firexxx.study.util;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * TODO
 *
 * @author fireXXX
 * @date 2020/11/17 0:25
 **/
public class BlockingQueueTest {

    public static void main(String[] args) throws InterruptedException {
        //容量若不设置队列的长度就是INT MAX
        BlockingQueue<Integer> blockingQueue = new LinkedBlockingQueue<>(10);

        //put当队列满时会阻塞等待
        blockingQueue.put(1);

        //put当队列满时会直接返回
        blockingQueue.offer(1);

        //put当队列空时会阻塞等待
        blockingQueue.take();

        //put当队列空时会直接返回
        blockingQueue.poll();
    }

}